<?php
class CommonAction extends Action {

    public function _initialize() {
        $this->_isUser();
        $this->_getFace();
        $this->_getNotRead();
        $this->_showNow();
    }

    public function _empty() {
        $this->redirect('./');
    }

    private function _isUser() {
        if(!cookie('user')) jump(__ROOT__.'/User/login');
    }

    private function _getFace() {
        $name = cookie('user');
        $user = M('User');
        $face = $user->where("name='$name'")->getField('face');
        $this->assign('face', $face);
    }

    protected function page($count, $pageSize='') {
        import('ORG.Util.Page');
        $pageSize = empty($pageSize) ? getSetting('admin_page') : $pageSize;
        $page = new Page($count, $pageSize);
        $this->limit = $page->firstRow.','.$page->listRows;
        $this->assign('page', $page->show());
    }

    private function _getNotRead() {
        $message = D('Message');
        //检查未读短信
        $map['mto'] = $_COOKIE['user'];
        $map['is_read'] = 0;
        $notRead = $message->where($map)->count('id');
        $this->assign('notread', $notRead);
    }

    private function _showNow() {
        $now = date('Y年m月d日 H时i分');
        $hour = date('H');
        switch ($hour) {
            case $hour>=6 && $hour<12:
                $this->assign('hello', '早上好');
                break;
            case $hour>=12 && $hour<18:
                $this->assign('hello', '下午好');
                break;
            case $hour>=18 && $hour<24:
                $this->assign('hello', '晚上好');
                break;
            case $hour>=0 && $hour<6:
                $this->assign('hello', '凌晨好');
                break;
        }
        $this->assign('now', $now);
    }



}


?>
